const express = require('express');
const { promisify } = require('util');
const {getListenPort} = require('./utils');
const config = require('./config');
const {responseTimeMiddleware} = require('./middwares');
const initController = require('./controller');

const PORT = getListenPort();

async function bootstrap() {
  const app = express();
  app.use(responseTimeMiddleware());
  app.use(express.static(config.SERVER.STATIC_PATH));
  // router
  app.use(await initController());
  await promisify(app.listen.bind(app, PORT))();
  console.log(`server is running at 127.0.0.1:${PORT}`)
}

bootstrap();
